﻿using System;

namespace Simp.CodeModel.CoreFunctions
{
	/// <summary>Encapsulates the sum of two expressions.</summary>
	/// <remarks>Simplifications can be done iif the left and right operand are numbers.</remarks>
	public class AdditionFunction : BinaryFunctionBase, IFunction
	{
		/// <summary>See <see cref="IFunction.FunctionName"/>.</summary>
		public override string FunctionName
		{
			get { return "Addition"; }
		}

		/// <summary>Returns an addition operation.</summary>
		/// <param name="a"/>
		/// <param name="b"/>
		/// <returns/>
		protected override IFunction IntegerOperation(int a, int b)
		{
			return new IntegerFunction(a + b);
		}

		/// <summary>Returns an addition operation.</summary>
		/// <param name="a"/>
		/// <param name="b"/>
		/// <returns/>
		protected override IFunction RationalOperation(RationalFunction a, RationalFunction b)
		{
			return RationalFunction.GetSimplified(
				a.Numerator * b.Denominator + b.Numerator * a.Denominator,
				a.Denominator * b.Denominator);
		}

		/// <summary>Returns an addition operation.</summary>
		/// <param name="a"/>
		/// <param name="b"/>
		/// <returns/>
		protected override IFunction RealOperation(double a, double b)
		{
			return new RealFunction(a + b);
		}

		/// <summary>Returns the symbol of the operation.</summary>
		protected override string OperationSymbol
		{
			get { return "+"; }
		}
	}
}